#!/bin/bash

#------------------------------------------------------------------------------
#Filename:	74870-cpio.sh
#Version:	1.1
#Date:	        2013/08/06
#Author:	yuanhui.shi
#Email:	        yuanhui.shi@cs2c.com.cn
#Summary:	02.01系统核心功能-06基础命令行工具-31cpio工具-02文件备份与提取
#Notes:	        备份文件命令
#Copyright:	China Standard Software Co.,Ltd.
#History:
#	        Version 1.0,2013/08/06
#	        -The first one
#	        Version 1.1,2013/09/09
#	        -Modify the script to satisfy the shell standard
#------------------------------------------------------------------------------


PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
export PATH

source ../../lib/Echo.sh

function CleanData ()
{
  cd ..
  rm -rf test

  EchoInfo "74870-cpio.sh执行完毕"
}

trap "CleanData" EXIT


cd /etc
VAR1=`ls -l *.conf |wc -l`
ls *.conf |cpio -o >etc_conf.cpio  
test "`file etc_conf.cpio`" == "etc_conf.cpio: cpio archive" 
EchoResult "备份文件存在"
mkdir test
mv etc_conf.cpio test
cd test
cpio -i < etc_conf.cpio &>/dev/null 
rm -rf etc_conf.cpio
VAR2=`ls -l *.conf |wc -l`
test "${VAR1}" == "${VAR2}" 
EchoResult "cpio提取文件正确"
